﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        public Dictionary<string, string> User = new Dictionary<string, string>();
       

        private void button1_Click(object sender, EventArgs e)
        { 
            string sqlserver = "server=.;database=Blogs;uid=sa;pwd=1361162012a";
            var uid = this.textBox1.Text.Trim();
            var pwd = this.textBox2.Text.Trim();
            SqlConnection sqlConnection = new SqlConnection(sqlserver);
            var str = string.Format("select Username,PassWord from Users where Username='" + uid+ "'and PassWord='"+pwd+"'",sqlConnection);
            var dt = DbHelp.dataTable(str);
            dataGridView1.DataSource = dt;

            if (dt.Rows.Count==1)
            {
                MessageBox.Show("登录成功");
               
               
                Form2 form2 = new Form2();
                form2.Show();
                

            }
            else
            {
                MessageBox.Show("登录失败,用户名或密码错误");
                this.Close();
            }
            
            //string sqlserver = "server=.;database=NewText;uid=sa;pwd=1361162012a";
            //var uid = this.textBox1.Text.Trim();
            //var pwd = this.textBox2.Text.Trim();
            //SqlConnection sqlConnection = new SqlConnection(sqlserver);
            //var str = string.Format("select UsaeName,PassWord from Users where UsaeName='" + uid + "'and PassWord='" + pwd + "'", sqlConnection);

            //sqlConnection.Open();
            //SqlCommand com = new SqlCommand(str, sqlConnection);
            //SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(com);
            //DataSet ds = new DataSet();
            //int n = sqlDataAdapter.Fill(ds, "Users");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
            Form3 form3 = new Form3();
            form3.Show();
        }
    }
}
